package com.example.wwk.graduationpractice.NetDataUtils;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.example.wwk.graduationpractice.Bean.FindEmailBean;
import com.example.wwk.graduationpractice.Bean.MaxQuestionIdBean;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by wwk on 2017/4/29.
 * 找回密码需要的网络数据
 */

public class FindPwdUtils {
    public static  final int GET_EMAIL = 777;
    public static void getEmail(String email,String username,final Handler handler){
        String Url = "http://192.168.191.1:9090/plugins/findpwd/getfindpwd?action=findemail";
        Url += "&email="+email+"&username="+username;
        final String finalUrl = Url;
        new Thread(new Runnable() {
            @Override
            public void run() {
                OkHttpClient client = new OkHttpClient();
                Request request = new Request.Builder()
                        .url(finalUrl)
                        .build();
                try {
                    FindEmailBean findEmailBean;
                    Response response = client.newCall(request).execute();
                    String responseData = response.body().string();
                    Log.d("123", "FindEmailBean run: "+responseData);
                    Gson gson = new Gson();
                    findEmailBean = gson.fromJson(responseData, new TypeToken<FindEmailBean>() {
                    }.getType());
                    Message msg=handler.obtainMessage(GET_EMAIL,findEmailBean);
                    msg.sendToTarget();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }).start();
    }
}
